<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>药品出入库信息</title>
    <!--引入本地的css和js-->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/admin/style.css}" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" action="">
                <input name="id" th:value="${obj?.id}" class="layui-input layui-hide"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">药品名称</label>
                    <div class="layui-input-block">
                        <select name="dname" id="dname" lay-filter="dname"></select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">药品批号</label>
                    <div class="layui-input-block">
                        <select name="druginnum" id="druginnum" lay-filter="druginnum"></select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出入库类型</label>
                    <div class="layui-input-block" th:style="'display:' + @{(${obj?.type != null} ? 'none' : '')} + ''">
                        <input type="radio" name="type" value="出库" title="出库">
                        <input type="radio" name="type" value="入库" title="入库">
                    </div>
                    <div class="layui-input-block" th:style="'display:' + @{(${obj?.type == null} ? 'none' : '')} + ''">
                        <input type="text" th:value="${obj?.type}" class="layui-input" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出入库数量</label>
                    <div class="layui-input-block">
                        <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" name="count"
                               th:value="${obj?.count}" lay-verify="required" placeholder="请输入药品的数量" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">操作人</label>
                    <div class="layui-input-block">
                        <input type="text" name="operator" th:value="${obj?.operator}" lay-verify="required" placeholder="请输入操作人" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-from-submit" id="LAY-from-submit" value="确认">
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script th:src="@{/static/layui/layui.js}"></script>
<script>
    layui.use(['form'], function () {
        var $ = layui.$;
        var form = layui.form;

        //当前药品的值
        var currentdname = '[[${obj?.dname}]]';
        //获取供应商列表
        $.ajax({
            url: '/drugInInfo/drugInInfoListOnly',
            dataType: 'json',
            type: 'post',
            cache: false,
            success: function (data) {
                $('#dname').prepend("<option value=''>请选择<option>");
                for (var i = 0; i < data.data.length; i++) {
                    if (data.data[i].name == currentdname) {
                        $('#dname').prepend("<option selected value='" + data.data[i].name + "'>" + data.data[i].name + "");
                    } else {
                        $('#dname').prepend("<option value='" + data.data[i].name + "'>" + data.data[i].name + "");
                    }

                }

                //下拉列表渲染
                form.render();
            }
        });
        form.on('select(dname)', function (d) {
            console.log(d.value); //得到被选中的值
            var nowdname = d.value;
            //当前药品的值
            var currentdruginnum = '[[${obj?.dname}]]';
            //获取药品编号列表
            $.ajax({
                url: '/drugInInfo/drugInInfoListByDrugName?dname=' + nowdname,
                dataType: 'json',
                type: 'post',
                cache: false,
                success: function (data) {
                    $('#druginnum').empty();
                    $('#druginnum').prepend("<option value=''>请选择<option>");
                    console.log(data);
                    for (var i = 0; i < data.data.length; i++) {
                        if (data.data[i].druginnum == currentdruginnum) {
                            $('#druginnum').prepend("<option selected value='" + data.data[i].druginnum + "'>" + data.data[i].druginnum + "</option>");
                        } else {
                            $('#druginnum').prepend("<option value='" + data.data[i].druginnum + "'>" + data.data[i].druginnum + "</option>");
                        }

                    }
                    data = undefined;
                    //下拉列表渲染
                    form.render();
                }
            });
        })

    });
</script>
</html>